
import mixins from './template'

import {
    HttpSysOrgList,
    HttpWarehouseList,
    HttpOrgList,
    HttpCarrierList,
    HttpProductList,
    HttpAllProductList,
    HttpAccountList,
    HttpCountryList,
    HttpCopeCusList,
    HttpCategory,
    HttpCusWareList,
    HttpCusOrgList,
    HttpCusAccountList,
    HttpWorkTypeList,
    HttpGetAllExcelModels,
    HttpGetAllExcelTypes,
    HttpFilterDisabledWarehouse,
    HttpAllNowManageOrgList,
    HttpSysList,
    HttpNowManageOrgList,
    HttpUserList,
    HttpNextOrgList,
    HttpBeforeOrgList,
    HttpWarehouseAllList,
    HttpHostAndFbaWarehouse,
    HttpUserManageWarehouse,
    HttpAreaList,
    HttpAreaListByCustomer,
    HttpProductLineAllList,
    HttpProductLineWithoutOrgAllList,
    HttpGetCarrierManageList,
    HttpGetCarrierCusList,
    HttpNextOrgSelfList,
    HttpGetAllActiveLogiticdProCodeList,
    HttpGetAllLogProCodeList,
    HttpGetAllLogProSerCodeList,
    HttpAllaccountType,
    HttpTransferWarehouse,
    HttpAdminTransferWarehouse,
    HttpBillTransferWarehouse,
    HttpTransferHostWarehouse
} from "../service/dictionary";


const list = [
    {
        name: 'nextOrgList',//当前组织的下属组织（云仓使用较多）
        ajaxRequest: HttpNextOrgList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: `${item.code}`
            }
        })),
    },
    {
        name: 'beforeOrgList',//当前组织的上属组织
        ajaxRequest: HttpBeforeOrgList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: `${item.code}`
            }
        })),
    },
    {
        name: 'sysorgList',//系统组织
        ajaxRequest: HttpSysOrgList,
        interceptResponse: data => data.content,
        formData: {
            page: 1,
            rows: 1000,
            sidx: 'id',
            sord: 'desc',
        },
        sortable: ['asc', 'name']
    }, 
    {
        name: 'warehouseList',//仓库
        ajaxRequest: HttpWarehouseList,
        interceptResponse: data => data.sort((pre, cur) => {
            return pre.code.toLowerCase() > cur.code.toLowerCase() ? 1 : -1
        }).map(item => {
            return {
                label: item.title ? `${item.code}(${item.title})` : item.code,
                value: item.id,
                attach: {
                    code: item.code,
                    warehouseType: item.warehouseType,
                }
            }
        }),

    }, {
        name: 'orgList',//当前所有组织
        ajaxRequest: HttpOrgList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: `${item.code}`
            }
        })),
    },
    // 全部系统下的全部组织
    {
        name: 'sysAllList',
        ajaxRequest: HttpSysList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: `${item.code}`
            }
        })),
    },
    {
        name: 'carrierServiceList',//查询所有承运商服务
        ajaxRequest: HttpCarrierList,
        interceptResponse: data => data.map(item => ({ 
            value: item.id, 
            label: `${item.carrierServiceCode}(${item.carrierServiceName})`, 
            attach: item 
        })),
    }, {
        name: 'productList',//项目
        ajaxRequest: HttpProductList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.name}(${item.description})`,
            attach: {
                name: `${item.name}`
            }
        })),
    },
    {
        name: 'newDifferentAllProductList',//项目(区分组织，包含已关闭，已停用)
        ajaxRequest: HttpAllProductList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.name}`,
            // attach: item
        })),
    },
    {
        name: 'newAllProductList',//全部项目（不分组织）
        ajaxRequest: HttpProductLineAllList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.name}`,
            attach: {
                name:`${item.name}`
            }
        })),
    },
    {
        name: 'newAllProductWithoutOrgList',//全部项目（不分组织,包含已关闭，已停用）
        ajaxRequest: HttpProductLineWithoutOrgAllList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.name}`,
            attach: {
                name:`${item.name}`
            }
        })),
    },
    {
        name: 'accountList',//渠道
        ajaxRequest: HttpAccountList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.title}(${item.flag})`,
            attach: {
                flag: item.flag,
                title: item.title,
                orgId: item.orgId
            }
        })),
    }, {
        name: 'countryList',//国家
        ajaxRequest: HttpCountryList,
        interceptResponse: data => data.map(item => ({
            value: item.code,
            label: `${item.nameEn}(${item.name})`,
            attach: {
                nameEn: item.nameEn,
                name: item.name,
                id: item.id,
            }
        })),
    }, {
        name: 'cusproductList',//cope项目
        ajaxRequest: HttpCopeCusList,
        interceptResponse: data => data.map(item => ({ value: item.id, label: item.name, attach: { name: item.name } })),
    }, {
        name: 'billcategory',//计费分类
        ajaxRequest: HttpCategory,
    },
    {
        name: 'billcusorgList',//管理组织
        ajaxRequest: HttpNextOrgList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: item.code,
                // warehouseType: item.warehouseType,
            }
        })),
    },
    {
        name: 'selfmanageorgList',//管理组织
        ajaxRequest: HttpNextOrgSelfList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: item.code,
                // warehouseType: item.warehouseType,
            }
        })),
    },
    {
        name: 'billcusWareList',//管理仓库
        ajaxRequest: HttpCusWareList,
        interceptResponse: data => data.map(item => ({
            value:item.id, label: `${item.code}(${item.title})`, attach: {
                title: item.title,
                code: item.code,
                warehouseType: item.warehouseType,
                active: item.active
            }
        })),
    },
    {
        name: 'billcusAndFbaWareList',//管理仓库和fba
        ajaxRequest: HttpHostAndFbaWarehouse,
        interceptResponse: data => data.map(item => ({
            value: item.code, label: `${item.code}(${item.title})`, attach: {
                title: item.title,
                code: item.code,
                warehouseType: item.warehouseType,
                active: item.active
            }
        })),
    }, {
        name: 'userManageWarehouseList',//用户管理仓库
        ajaxRequest: HttpUserManageWarehouse,
        interceptResponse: data => data.map(item => ({
            value: item.code, label: `${item.code}(${item.title})`, attach: {
                title: item.title,
                code: item.code,
                warehouseType: item.warehouseType,
                active: item.active,
                id:item.id
            }
        })),
    },  {
        name: 'cusAccountList',//管理端渠道
        ajaxRequest: HttpCusAccountList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.title}(${item.flag})`,
            attach: {
                flag: item.flag,
                title: item.title,
                orgId: item.orgId
            }
        })),
    },
    // 事物类型包含
    {
        name: 'workTypeList',
        ajaxRequest: HttpWorkTypeList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: `${item.transactionCode}(${item.transactionName})`, attach: item
        })),
        formData: {
            status: 1
        },
    },
    // 事物类型包含管理端
    {
        name: 'workTypeManageList',
        ajaxRequest: HttpWorkTypeList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: `${item.transactionCode}(${item.transactionName})`, attach: item
        })),
        formData: {
            status: 0
        },
    },
    // 所有附件模块
    {
        name: 'allExcelModels',
        ajaxRequest: HttpGetAllExcelModels,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.code, attach: item
        })),
    },
    // 所有附件类型
    {
        name: 'allExcelTypes',
        ajaxRequest: HttpGetAllExcelTypes,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.title, attach: item
        })),
    },
    {
        name: 'filterDisabledWarehouse',//过滤掉禁用状态的仓库
        ajaxRequest: HttpFilterDisabledWarehouse,
        interceptResponse: data => data.map(item => ({
            label: item.title ? `${item.code}(${item.title})` : item.code,
            value: item.id,
            attach: {
                code: item.code,
                warehouseType: item.warehouseType,
            }
        })),
    },
    // 当前组织下的全部管理组织
    //
    {
        name: 'allNowManageOrgList',//当前组织下的全部管理组织
        ajaxRequest: HttpAllNowManageOrgList,
        interceptResponse: data => data.map(item => ({
            value: item.id, label: item.name, attach: {
                code: item.code,
            }
        })),
    },

    {
        name: 'allProductPerson',
        ajaxRequest: HttpUserList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.name}`,
        })),
    },
    {
        name: 'newAllWarehouseIdList',//全部仓库（不分组织）
        ajaxRequest: HttpWarehouseAllList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.code}(${item.title})`,
            attach: {
                code:item.code,
                warehouseType:item.warehouseType,
                orgId:item.organizationId,
                apiType:item.apiType
            }
        })),
    }, {
        name: 'areaList',//区域管理
        ajaxRequest: HttpAreaList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.areaName}`,
            attach: {
                name: item.areaName,
                id: item.id,
            }
        })),
    }, {
        name: 'customerAreaList',//国家
        ajaxRequest: HttpAreaListByCustomer,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: `${item.areaName}`,
            attach: {
                name: item.areaName,
                id: item.id,
            }
        })),
    }, 
    // 承运商分组  客户端(目前b2c订单模块使用) --管理端暂时用不到，先不写
    {
        name: 'carrierCusList',
        ajaxRequest: HttpGetCarrierCusList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: item.groupName,
            // attach: {
            //     name: item.areaName,
            //     id: item.id,
            // }
        })),
    },
    // 承运商分组 管理端专用
    {
        name: 'carrierManageList',
        ajaxRequest: HttpGetCarrierManageList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: item.groupName,
        })),
        
    },
    // 请求全部物流产品服务的有效code
    {
        name: 'logiticdProCodeList',
        ajaxRequest: HttpGetAllActiveLogiticdProCodeList,
        interceptResponse: data => data.map(item => ({
            value: item.code,
            label: item.code,
        })),
        
    },
    // 物流商模块使用的物流产品和物流产品服务的下拉（包含失效与有效）
    {
        name: 'alllogProCodeList',
        ajaxRequest: HttpGetAllLogProCodeList,
        interceptResponse: data => data.map(item => ({
            value: item.id,
            label: item.groupName,
            attach:{
                id:item.id,
            }
        })),
        
    },
    {
        name: 'alllogProSerCodeList',
        ajaxRequest: HttpGetAllLogProSerCodeList,
        interceptResponse: data => data.map(item => ({
            value: item.code,
            label: item.code+'('+item.carrierServiceName+')',
            attach:{
                id:item.id,
            }
        })),
    },
    // 渠道类型（店铺类型）
    {
        name: 'allAccountType',
        ajaxRequest: HttpAllaccountType,
        interceptResponse: data => data.map(item => ({
            value: item.name,
            label: item.name,
            attach:{
                id:item.id,
            }
        })),
    },
    // 库存报表-仓库-客户端-包含中转仓
    {
        name: "transferWarehouse",
        ajaxRequest: HttpTransferWarehouse,
        interceptResponse: data => data.map(item => ({
            label: `${item.code}(${item.title})`,
            value: item.id,
            attach: {
                id: item.id,
                code: item.code
            }
        })),
    },
    // 库存报表-仓库-管理端-包含中转仓
    {
        name: "adminTransferWarehouse",
        ajaxRequest: HttpAdminTransferWarehouse,
        interceptResponse: data => data.map(item => ({
            label: `${item.code}(${item.title})`,
            value: item.code,
            attach: {
                id: item.id,
                code: item.code
            }
        })),
    },
    // 计费-仓库包含中转仓
    {
        name: 'billTransferWarehouse',//管理仓库
        ajaxRequest: HttpBillTransferWarehouse,
        interceptResponse: data => data.map(item => ({
            value:item.id, label: `${item.code}(${item.title})`, attach: {
                title: item.title,
                code: item.code,
                warehouseType: item.warehouseType,
                active: item.active
            }
        })),
    },
    {
        name: "transferHostWarehouse",
        ajaxRequest: HttpTransferHostWarehouse,
        interceptResponse: data => data.map(item => ({
            value:item.id, 
            label: `${item.code}(${item.title})`, 
            attach: {
                title: item.title,
                code: item.code,
            }
        })),
    },
    
]
export default mixins(list,
    {
    getters: {
        getCarrierList(state, getters) {
            const carrierList = [], carrierServiceList = getters.getCarrierServiceList || []
            carrierServiceList.forEach(item => {
                const carrierCode = item.attach.carrierCode;
                const bool = carrierList.some(ele => {
                    return ele.value === carrierCode
                })
                if (!bool) carrierList.push({
                    label: carrierCode,
                    value: carrierCode,
                    attach: item.attach
                })
            })
            return carrierList
        },
        getWarehouseAllList(state, getters) {
            return [{
                label: 'Other',
                value: 0,
                attach: {
                    warehouseType: 0,
                    code: "Other"
                }
            }, ...getters.getWarehouseList]
        },
        getFilterDisabledAllWarehouse(state, getters) {
            return [{
                label: 'Other',
                value: '',
                attach: {
                    warehouseType: 0,
                    code: "Other"
                }
            }, ...getters.getFilterDisabledWarehouse]
        },
        getFBBFilterDisabledAllWarehouse(state, getters) {
            return [{
                label: 'Other',
                value: 0,
                attach: {
                    warehouseType: 0,
                    code: "Other"
                }
            }, ...getters.getFilterDisabledWarehouse]
        },
        getTransferOtherWarehouse(state, getters) {
            return [{
                label: "Other",
                value: 0,
                attach: {
                    warehouseType: 0,
                    code: "Other"
                }
            }, ...getters.getTransferWarehouse]
        },

        // value: item.id, label: item.name, attach: {
            //             code: item.code,
            //             warehouseType: item.warehouseType,
            //         }
        //管理组织(之前管理组织那个接口要替换成这个)
        getManageorgList(state, getters){
            let sysalllist = getters.getSysAllList || [];
            var manageList = [];
            let billList = [];
            HttpNowManageOrgList().then(res=>{
                manageList = res.data.accessResourceIds
                sysalllist.map(item=>{
                    // console.log(item)
                    manageList.map(json=>{
                        // console.log(json)
                        if(item.value === json){
                            billList.push(item)
                        }
                    })
                })
            })
            return billList
        }
    }
})
